package org.whb.basic.util;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.whb.user.domain.Logininfo;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

public class LoginContext {

    public static Logininfo getLogininfo(HttpServletRequest request){


        String token = request.getHeader("token");

        if (token!=null){
            WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());

            RedisTemplate redisTemplate =(RedisTemplate) webApplicationContext.getBean("redisTemplate");

            Object logininfo = redisTemplate.opsForValue().get(token);

            return (Logininfo)logininfo;
        }

       return null;

    }

}
